﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapTXTIND(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveTXTIND(DataRow dwData)
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;

            setResult = QueryTXTIND(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapTXTIND(ref dwLocal, dwData);
            if (!flgExist)
            {
                InsertTXTIND(dwLocal);
            }
            UpdateTXTIND(dwLocal);
        }
        
        public void InsertTXTIND(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "INSERT INTO TXTIND(TXTIMANDANT, TXTITXTART, TXTISIND, TXTISPRACHKZ, TXTIPIND, TXTITITEL, TXTINURERGAENZ, TXTISAPTEXTART, TXTISTARTENDE, TXTIKZPERS, TXTIAENDBEN, TXTIAENDDAT, TXTINEUBEN, TXTINEUDAT, TXTIAENDZL, TXTILPOS, TXTIUPDT, TXTIRICHEDIT, TXTIFILLER)"
            + " VALUES (:TXTIMANDANT, :TXTITXTART, :TXTISIND, '  ', :TXTIPIND, '                              ', ' ', '    ', ' ', ' ', '        ', 0, :TXTINEUBEN, :TXTINEUDAT, 1, 0, 'J', ' ', '                    ')";
            or1.Parameters.Add("TXTIMANDANT", OracleType.NVarChar).Value = dwData["TXTIMANDANT"];
            or1.Parameters.Add("TXTITXTART", OracleType.NVarChar).Value = dwData["TXTITXTART"];
            or1.Parameters.Add("TXTISIND", OracleType.NVarChar).Value = dwData["TXTISIND"];
            or1.Parameters.Add("TXTIPIND", OracleType.NVarChar).Value = dwData["TXTIPIND"];
            or1.Parameters.Add("TXTINEUBEN", OracleType.NVarChar).Value = dwData["TXTINEUBEN"];
            or1.Parameters.Add("TXTINEUDAT", OracleType.NVarChar).Value = dwData["TXTINEUDAT"];
            Connect2Proxy(or1);
        }
        public DataSet QueryTXTIND(DataRow dwInput, int option = 1)
        {
            DataSet SReturn = new DataSet();
            DataSet SResult = new DataSet();
            DataTable tbLocal = null;
            or1 = OracleDB.CreateCommand();
            string key = "";
            switch (option)
            {
                case 1:
                    or1.CommandText = "SELECT *  FROM TXTIND T  "
                        + " WHERE TXTIMANDANT=:TXTIMANDANT AND TXTIPIND=:TXTIPIND";
                    or1.Parameters.Add("TXTIMANDANT", OracleType.NVarChar).Value = dwInput["TXTIMANDANT"];
                    or1.Parameters.Add("TXTIPIND", OracleType.NVarChar).Value = dwInput["TXTIPIND"];
                    break;
                case 2:
                    or1.CommandText = "SELECT *  FROM TXTIND T  "
                                  + " WHERE TXTIMANDANT=:TXTIMANDANT AND TXTISIND=:TXTISIND AND TXTITXTART=:TXTITXTART"
                                  + " ORDER BY 1,2,3,4";
                    or1.Parameters.Add("TXTIMANDANT", OracleType.NVarChar).Value = dwInput["TXTIMANDANT"];
                    or1.Parameters.Add("TXTITXTART", OracleType.NVarChar).Value = dwInput["TXTITXTART"];
                    or1.Parameters.Add("TXTISIND", OracleType.NVarChar).Value = dwInput["TXTISIND"];
                    break;
                case 3:
                    or1.CommandText = "SELECT MAX(TXTIPIND) AS TXTIPIND FROM TXTIND WHERE TXTIMANDANT=:TXTIMANDANT";
                    or1.Parameters.Add("TXTIMANDANT", OracleType.NVarChar).Value = dwInput["TXTIMANDANT"];
                    break;
                default:
                    break;
            }
            SResult = Connect2Proxy(or1);
            if (SResult.Tables.Count > 0)
            {
                tbLocal = SResult.Tables[0];
                tbLocal.TableName = "TXTIND";
            }
            SReturn.Merge(SResult);



            return SReturn;
        }
        public void UpdateTXTIND(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE TXTIND SET "
            + "TXTITXTART=:TXTITXTART,"
            + "TXTISIND=:TXTISIND,"
            + "TXTISPRACHKZ=:TXTISPRACHKZ,"
            + "TXTITITEL=:TXTITITEL,"
            + "TXTINURERGAENZ=:TXTINURERGAENZ,"
            + "TXTISAPTEXTART=:TXTISAPTEXTART,"
            + "TXTISTARTENDE=:TXTISTARTENDE,"
            + "TXTIKZPERS=:TXTIKZPERS,"
            + "TXTIAENDBEN=:TXTIAENDBEN,"
            + "TXTIAENDDAT=:TXTIAENDDAT,"
            + "TXTINEUBEN=:TXTINEUBEN,"
            + "TXTINEUDAT=:TXTINEUDAT,"
            + "TXTIAENDZL=:TXTIAENDZL,"
            + "TXTILPOS=:TXTILPOS,"
            + "TXTIUPDT=:TXTIUPDT,"
            + "TXTIRICHEDIT=:TXTIRICHEDIT,"
            + "TXTIFILLER=:TXTIFILLER"
            + " WHERE TXTIMANDANT=:TXTIMANDANT  AND TXTIPIND=:TXTIPIND";

            or1.Parameters.Add("TXTIMANDANT", OracleType.NVarChar).Value = dwData["TXTIMANDANT"].ToString();
            or1.Parameters.Add("TXTITXTART", OracleType.NVarChar).Value = dwData["TXTITXTART"].ToString();
            or1.Parameters.Add("TXTISIND", OracleType.NVarChar).Value = dwData["TXTISIND"].ToString();
            or1.Parameters.Add("TXTISPRACHKZ", OracleType.NVarChar).Value = dwData["TXTISPRACHKZ"].ToString();
            or1.Parameters.Add("TXTIPIND", OracleType.NVarChar).Value = dwData["TXTIPIND"].ToString();
            or1.Parameters.Add("TXTITITEL", OracleType.NVarChar).Value = dwData["TXTITITEL"].ToString();
            or1.Parameters.Add("TXTINURERGAENZ", OracleType.NVarChar).Value = dwData["TXTINURERGAENZ"].ToString();
            or1.Parameters.Add("TXTISAPTEXTART", OracleType.NVarChar).Value = dwData["TXTISAPTEXTART"].ToString();
            or1.Parameters.Add("TXTISTARTENDE", OracleType.NVarChar).Value = dwData["TXTISTARTENDE"].ToString();
            or1.Parameters.Add("TXTIKZPERS", OracleType.NVarChar).Value = dwData["TXTIKZPERS"].ToString();
            or1.Parameters.Add("TXTIAENDBEN", OracleType.NVarChar).Value = dwData["TXTIAENDBEN"].ToString();
            or1.Parameters.Add("TXTIAENDDAT", OracleType.NVarChar).Value = dwData["TXTIAENDDAT"].ToString();
            or1.Parameters.Add("TXTINEUBEN", OracleType.NVarChar).Value = dwData["TXTINEUBEN"].ToString();
            or1.Parameters.Add("TXTINEUDAT", OracleType.NVarChar).Value = dwData["TXTINEUDAT"].ToString();
            or1.Parameters.Add("TXTIAENDZL", OracleType.NVarChar).Value = dwData["TXTIAENDZL"].ToString();
            or1.Parameters.Add("TXTILPOS", OracleType.NVarChar).Value = dwData["TXTILPOS"].ToString();
            or1.Parameters.Add("TXTIUPDT", OracleType.NVarChar).Value = dwData["TXTIUPDT"].ToString();
            or1.Parameters.Add("TXTIRICHEDIT", OracleType.NVarChar).Value = dwData["TXTIRICHEDIT"].ToString();
            or1.Parameters.Add("TXTIFILLER", OracleType.NVarChar).Value = dwData["TXTIFILLER"].ToString();
            Connect2Proxy(or1);
        }
    }
}
